<template>
  <view class="content">
    <view class="">
      <uni-row :gutter="20">
        <uni-col :span="6"> 账号 </uni-col>
        <uni-col :span="18">
          <input v-model="loginName" class="uni-input" placeholder="请输入账号">
        </uni-col>
      </uni-row>
      <uni-row :gutter="20">
        <uni-col :span="6"> 密码 </uni-col>
        <uni-col :span="18">
          <input v-model="password" class="uni-password" password placeholder="请填写密码">
        </uni-col>
      </uni-row>
      <uni-row :gutter="20" class="row-action">
        <uni-col :span="24">
          <button type="primary" :loading="loading" @click="handleSubmit()">登录</button>
        </uni-col>
      </uni-row>
    </view>
  </view>
</template>

<script>
import request from '@/util/request.js'
export default {
  data() {
    return {
      loading: false,
      loginName: '',
      password: ''
    }
  },
  onLoad() {},
  methods: {
    handleSubmit() {
      const vue = this
      const paramLogin = {
        loginName: this.loginName,
        passwd: this.password
      }
      request.requestApi('/home/login', 'POST', paramLogin).then(res => {
        if (res.code === 0) {
          uni.setStorageSync('token', res.token)
          uni.setStorageSync('user', res.user)
          uni.showToast({
            title: '登录成功',
            icon: 'success'
          })
          setTimeout(function() {
            uni.switchTab({
              url: '/pages/index/index'
            })
          }, 1000)
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    }
  }
}
</script>

<style>
.content {
  padding: 20upx;
}
.content .uni-row {
  margin: 20upx 0;
}
</style>
